<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .mark {
            width: 100%;
            height: 100%;
            position: absolute;
            top: 0;
            background: rgba(0, 0, 0, .4);
        }

        .text {
            width: 200px;
            height: 200px;
            position: absolute;
            top: 200px;
            left: 100px;
            background-color: aliceblue;
        }
    </style>
    <div id="app">
        <h4 v-show="filterList.length>0">
            我的兴趣爱好：
            <span v-for="(item,index) in filterList"  >
                {{item.title}}--
            </span>
        </h4>
        <button @click="isShow">点击</button>
        <my-dialog v-show="flag" @send="changeFlag"></my-dialog>
    </div>

    <!-- 弹框 -->
    <template id="dialog">
        <div class="mark">
            <div class="text">
                <ul>
                    <li v-for="(item , index) in list">
                        <input v-model="item.check" type="checkbox">
                        {{item.title}}
                    </li>
                </ul>
                
                <button @click="cancel">取消</button>

                <button @click="success">确定</button>
            </div>
        </div>
    </template>

    <script src="./vue.js"></script>
    <script>

        const Dialog = {
            template: "#dialog",
            data() {
                return {
                    list: [
                        {
                            title: "篮球",
                            check: false
                        },
                        {
                            title: "足球",
                            check: false
                        },
                        {
                            title: "排球",
                            check: false
                        }
                    ]
                }
            },
            methods: {
                //取消
                cancel() {
                    this.$emit("send", {
                        flag:false
                    })
                },
                //确定
                success(){
                    this.$emit("send", {
                        flag:false,
                        list:JSON.parse(JSON.stringify(this.list))
                    })

                },
            }
        }

        new Vue({
            el: "#app",
            computed:{
                filterList(){
                    return this.list.filter(item=>item.check)
                },
            },
            data() {
                return {
                    flag: false,
                    list:[]
                }
            },
            components: {
                "my-dialog": Dialog
            },
            methods: {
                isShow() {
                    this.flag = true
                },
                //取消
                changeFlag({flag,list}) {
                    this.flag=flag
                    //点击了确定
                    if (list) {
                        this.list=list
                    }
                    
                }
            }
        })
    </script>
</body>

</html>